package com.memexue.order.message;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MqReceiver {
//    @RabbitListener(queuesToDeclare = @Queue("myQueue"))
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("myQueue"),
            exchange = @Exchange("myExchange")
    ))
    public void process(String message){
        log.info("mq message receiver={}", message);
    }

    /**
     * 模拟数码供应商接收消息
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("computerOrderQueue"),
            // 只接收computer类型消息
            key = "computer",
            exchange = @Exchange("OrderExchange")
    ))
    public void processComputer(String message){
        log.info("computer mq receiver={}", message);
    }
    /**
     * 模拟水果供应商接收消息
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("fruitOrderQueue"),
            // 只接收fruit类型消息
            key = "fruit",
            exchange = @Exchange("OrderExchange")
    ))
    public void processFruit(String message){
        log.info("fruit mq receiver={}", message);
    }
}